import {
	sub
} from '@/common/event.js'

import store from '@/store/index.js'
import {getRqst} from '@/common/request.js'
export default {
	namespaced: true,
	state: {
		appname: "-"
	},
	mutations: {
		setNameState: (state, payload) => {
			state.appname = payload
		}
	},
	actions: {
		setName({
			commit
		}, {
			payload
		}) {
			console.log("vuex action", payload)
			commit('setNameState', payload)
		},
		async getInfo({
			commit
		}, {
			payload
		}) {
			const ret = await getRqst().get(`common/common/getSystemInfo`)
			store.commit(`systemInfo/setNameState`,ret.data.appname)
		},
	},
	init: async function() {
		const ret = await getRqst().get(`common/common/getSystemInfo`)
		store.commit(`systemInfo/setNameState`,ret.data.appname)
		sub(`loginSuccess`, function() {
			store.dispatch(`systemInfo/getInfo`)
		})
	}
}